home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / RNdeleteUnused.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.3 KB  |  134 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //
  19. //  Procedure Name:
  20. //      RNdeleteUnused
  21. //
  22. //  Description:
  23. //         Delete unused reference nodes.
  24. //        
  25. //  Input Arguments:
  26. //      None.
  27. //
  28. //  Return Value:
  29. //      None.
  30. //
  31.  
  32. proc string[] getUsedReferenceNodes(string $sceneFile)
  33. //
  34. //    Description:
  35. //        Returns all of the reference nodes used by a scene and its 
  36. //        references.
  37. //
  38. {
  39.     int $index = 0;
  40.     string $referenceNodes[];
  41.  
  42.     string $referenceFiles[];
  43.     if (size($sceneFile) == 0) {
  44.         //    Get all of the references from the top-level scene.
  45.         //
  46.         $referenceFiles = `file -q -r`;
  47.     } else {
  48.         $referenceFiles = `file -q -r $sceneFile`;
  49.     }
  50.  
  51.     int $i;
  52.     int $nRefs = `size($referenceFiles)`;
  53.     for ($i = 0; $i < $nRefs; $i++) {
  54.         //    Skip the untitled scene case.
  55.         //
  56.         if (size($referenceFiles[$i]) == 0) {
  57.             continue;
  58.         }
  59.  
  60.         string $rn = `file -q -rfn $referenceFiles[$i]`;
  61.         if (size($rn) > 0) {
  62.             $referenceNodes[$index++] = $rn;
  63.         }
  64.  
  65.         string $rnList[] = getUsedReferenceNodes($referenceFiles[$i]);
  66.         int $j;
  67.         int $nChildren = size($rnList);
  68.         for ($j = 0; $j < $nChildren; $j++) {
  69.             $referenceNodes[$index++] = $rnList[$j];
  70.         }
  71.     }
  72.  
  73.     return $referenceNodes;
  74. }
  75.  
  76. proc deleteReferenceNode(string $refNode) 
  77. //
  78. //    Description:
  79. //        Delete the reference node if there are no connections made to it.
  80. //
  81. {
  82.     string $connectionList[] = `listConnections $refNode`;
  83.     int $numConnections = `size($connectionList)`;
  84.     if ($numConnections == 0) {
  85.         string $cmd = ("delete " + $refNode);
  86.         evalEcho ($cmd);
  87.     }
  88. }
  89.  
  90. global proc RNdeleteUnused() 
  91. //
  92. //    Description:
  93. //        Deletes unused reference nodes.
  94. //
  95. {
  96.     string $rnList[] = `ls -type reference`;
  97.     int $nRefs = size($rnList);
  98.     if ($nRefs == 0) {
  99.         //    There are no reference nodes to delete.
  100.         //
  101.         return;
  102.     }
  103.  
  104.     //    Get all of the reference nodes associated with a scene.
  105.     //
  106.     string $rnUsedList[] = getUsedReferenceNodes("");
  107.  
  108.     int $i;
  109.     for ($i = 0; $i < $nRefs; $i++) {
  110.         if (!size(`ls -ro $rnList[$i]`)) {
  111.             //    This may be an unused reference node.
  112.             //
  113.             int $found = false;
  114.             for ($nextRef in $rnUsedList) {
  115.                 if ($nextRef == $rnList[$i]) {
  116.                     $found = true;
  117.                     break;
  118.                 }
  119.             }
  120.  
  121.             if ($found) {
  122.                 //    This reference node is being used, so it should not be
  123.                 //    deleted.
  124.                 //
  125.                 continue;
  126.             }
  127.  
  128.             //    Delete the reference node.
  129.             //
  130.             deleteReferenceNode($rnList[$i]);
  131.         }
  132.     }
  133. }
  134.